<?php
class MailModel extends MetaModel
{
	protected $_validate  = array(
		array ('touid','require','收信人ID不能为空',1,'',1),
			array ('title','require','标题不能为空',1,'',1),
			array ('content','require','消息内容不能为空',1,'',1),
			
		);
		
	
	protected $_auto = array(
		array ('fromuid','UserID',1,'function'),
		array ('createtime','time',1,'function'),
		array ('status','1')
		);
		

	/**
	 * 返回消息列表
	 */
	function getMails()
	{
		$sql = "SELECT sz_user.id as uid,sz_user.cnname,sz_mail.id,sz_mail.title,sz_mail.createtime,sz_mail.status
		from sz_user,sz_mail 
		where sz_mail.status <> 2 and sz_user.id = sz_mail.fromuid and sz_mail.touid=".UserID()." order by sz_mail.createtime desc";
		return $this->query($sql);
	}
	
	function getMail($id)
	{
		$result = $this->query("SELECT sz_user.id as uid,sz_user.cnname,sz_mail.id,sz_mail.title,sz_mail.createtime,sz_mail.status,sz_mail.content
		from sz_user,sz_mail
		where sz_mail.id=$id and sz_user.id = sz_mail.fromuid and sz_mail.status <> 2 ");
		return $result[0];
	}
}
?>